<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>支付订单</title>
<link href="__PUBLIC__/logic/shop/weixin/css/shop.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/logic/shop/weixin/js/jquery.js" charset="utf-8"></script>
<script type="text/javascript" src="__PUBLIC__/logic/shop/weixin/js/ecmall.js" charset="utf-8"></script>
<script type="text/javascript" src="__PUBLIC__/logic/shop/weixin/js/touchslider.dev.js" charset="utf-8"></script>
<script type="text/javascript">
//<!CDATA[
var SITE_URL = "http://store.weiapps.cn";
var REAL_SITE_URL = "http://store.weiapps.cn";
var PRICE_FORMAT = '¥%s';

$(function(){
    var span = $("#child_nav");
    span.hover(function(){
        $("#float_layer:not(:animated)").show();
    }, function(){
        $("#float_layer").hide();
    });
});
//]]>
</script>
</head>
<body>
<include file="User/bookhead" />
<div id="content" style="top: 45px;">
    <form action="{:U('User/pay')}" method="POST" id="goto_pay">
    <input type="hidden" name="orderid" id="orderid" value="{$orderid}" />
       <input type="hidden" name="dingdanhao" id="dingdanhao" value="{$dingdanhao}" />
        <div class="step_main">
            <div class="clue_on"><h4>订单详情：</h4></div>
            <div class="order_information">
                    <p>订单号：<span>{$dingdanhao}</span></p>订单总价：<span>¥ {$order_sumPrice}</span>
            </div>
            <div class="buy">
                <h3>订单支付：</h3>
                    <dl class="defray">
						<notempty name="paylist">
                      <switch name="paylist" >
                      <case value="wxpay">
					    <dt>微信支付,更便捷</dt>
                        <dd>
					        <p class="radio"><input  id="payment_alipay" name="payment_id" value="wxpay" onclick="callpay()" type="radio"></p>
                            <p class="logo"><label for="payment_alipay"><img src="__PUBLIC__/logic/shop/weixin/images/wxpay.jpg" ></label></p>
						</dd>
					  </case>
                      <case value="hdfk">
					    <dt>货到付款,更贴心</dt>
                        <dd>
					        <p class="radio"><input  id="payment_alipay" name="payment_id" onclick="formpay()" value="hdfk" type="radio"></p>
                            <p class="logo"><label for="payment_alipay"><img src="__PUBLIC__/logic/shop/weixin/images/huodao.png" ></label></p>
						</dd>
				      </case>
                      <default />
					    <dt>微信支付,更便捷</dt>
                        <dd>
					        <p class="radio"><input  id="payment_alipay" name="payment_id" onclick="callpay()" value="wxpay" type="radio"></p>
                            <p class="logo"><label for="payment_alipay"><img src="__PUBLIC__/logic/shop/weixin/images/wxpay.jpg" ></label></p>
						</dd>
                        <dd>
					        <p class="radio"><input id="payment_alipay" name="payment_id" onclick="formpay()" value="hdfk" type="radio"></p>
                            <p class="logo"><label for="payment_alipay"><img src="__PUBLIC__/logic/shop/weixin/images/huodao.png" ></label></p>
						</dd>
                          </switch>
						</notempty>
                    </dl>
					<notempty name="hblist">
                    <dl class="defray">
                        <dt>红包抵用,更优惠</dt>
                        <dd>
                            <p class="radio">
							<select name="payment_hb" id="hongbao">
							<option value="0">暂不使用红包</option>
							<volist name='hblist' id='vo' >
							<option value="{$vo.id}">{$vo.hb_title}-面值{$vo.hb_value}</option>
							</volist>
							</select>
                            </p>
                        </dd>
                    </dl>   
                    </notempty>        
            </div>
			<!---
            <div class="make_sure">
                <p>
                    <a href="javascript:$('#goto_pay').submit();" class="btn enter" style="background-image: linear-gradient(to bottom,#00FF3D,#227408);">确认支付</a>
                </p>
            </div>
			-->
            <div class="clear"></div>
            <input type="hidden" id="payparams" value="{$payparams}" />
        </div>
    </form>
</div>
</body>
<script language="javascript">
<notempty name="payparams">
        //调用微信JS api 支付
        function jsApiCall(){
	   var data = new Object();
		 data.dingdanhao = $('#dingdanhao').val();
		 data.orderid    = $('#orderid').val();
		 data.payment_id = $('#payment_alipay').val();
         data.payment_hb = $('#hongbao option:selected').val();
      var payparams = '';
	      payparams = $('#payparams').val();
            WeixinJSBridge.invoke(
                "getBrandWCPayRequest",
                {$payparams},
                function(res){
				    //用户取消支付
				    if(res.err_msg == "get_brand_wcpay_request:cancel"){
						location.href="{:U('User/bookprofile')}";
					} else {
                         if(res.err_msg == "get_brand_wcpay_request:ok"){
		  $.post("{:U('User/orderpay')}",data,function(d){
			 if(d.status!=0){
			      alert(d.msg);
             }else{
	              alert(d.msg);
			 }
			      location.href="{:U('User/bookprofile')}";
		  },'json');
						 }else {
                             alert('支付失败!');
							 location.href="{:U('User/bookprofile')}";
						 }
					}
                         // WeixinJSBridge.log(res.err_msg);
                }
            );
        }
        function callpay(){
            if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                }else if (document.attachEvent){
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            }else{
                jsApiCall();
            }
        }
 </notempty>
       function formpay(){
	   var data = new Object();
		 data.dingdanhao = $('#dingdanhao').val();
		 data.orderid    = $('#orderid').val();
		 data.payment_id = $('#payment_alipay').val();
         data.payment_hb = $('#hongbao option:selected').val();

		  $.post("{:U('User/orderpay')}",data,function(d){
			 if(d.status!=0){
			      alert(d.msg);
             }else{
	              alert(d.msg);
			 }
			      location.href="{:U('User/bookprofile')}";
		  },'json');
        }
 </script>
</html>